<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

function smarty_modifier_SongTruncate($string, $length=80, $symbol='...',$code='utf-8',$start=0){
	$sy = $code=='utf-8' ? 3 : 2;
	$chars = $string;   
	$i=0;   
	while($k < $length){   
		if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){  
			$m++;   
		} else {  
			$n++;
		}
		$k = $n/$sy+$m/2;   
		$l = $n/$sy+$m; 
		$i++;
	} 
	$str1 = iconv_substr($string,$start,$l,$code);
	if((strlen($string)-$m-$n) > 0) $str1 .= $symbol;
	return $str1; 
}
?>
